import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_app/app/modules/shared_preferences_tool/shared_preferences_tool_controller.dart';
import 'package:my_app/app/core/theme/app_text_theme.dart';

/// shared_preferences_tool_page.dart
///
/// Created by fuchuanwei on Tue Feb 21 2023.
///
/// Description:
///
class SharedPreferencesToolPage extends GetView<SharedPreferencesController> {
  @override
  Widget build(BuildContext context) {
    Get.put(SharedPreferencesController());
    return Scaffold(
      appBar: AppBar(title: Text('Shared Preferences 数据存储')),
      body: ListView(
        padding: EdgeInsets.all(10.0),
        children: [basicDemo()],
      ),
    );
  }

  //基础示例
  Widget basicDemo() {
    return Card(
      child: Padding(
        padding: EdgeInsets.all(10.0),
        child: Column(
          children: [
            Text(
              '基础使用示例',
              style: cardTitle,
            ),
            SizedBox(height: 20),
            Text(
              '本地存储值为:',
              style: tips,
            ),
            Container(
              width: double.infinity,
              padding: EdgeInsets.all(10.0),
              decoration: BoxDecoration(
                color: Colors.grey[300],
                borderRadius: BorderRadius.circular(10.0),
              ),
              child: Obx(
                () => Text(controller.storeValue.value),
              ),
            ),
            SizedBox(height: 20),
            TextField(
              onChanged: controller.changeFieldValue,
              decoration: InputDecoration(
                contentPadding:
                    EdgeInsets.symmetric(horizontal: 10.0, vertical: 5.0),
                border: OutlineInputBorder(),
                hintText: "输入需要存储的值",
                labelText: "存储",
              ),
            ),
            SizedBox(height: 20),
            SizedBox(
              width: double.infinity,
              child: OutlinedButton(
                onPressed: () => controller.changeStoreValue(),
                child: Text('点击存储'),
              ),
            )
          ],
        ),
      ),
    );
  }
}
